package cn.changshengjue.dakong.command;

import org.bukkit.Bukkit;

import cn.changshengjue.dakong.command.sub.ExamplesCommand;
import cn.changshengjue.dakong.command.sub.GiveCommand;
import cn.changshengjue.dakong.command.sub.ItemCommand;
import cn.changshengjue.dakong.command.sub.ReloadCommand;
import cn.changshengjue.dakong.command.sub.SetCommand;
import cn.changshengjue.dakong.command.sub.StartCommand;

import java.util.HashSet;
import java.util.Set;

public class CommandHandler {

	private Set<SubCommand> commands = new HashSet<SubCommand>();

	public CommandHandler(String name) {
		Bukkit.getPluginCommand(name).setExecutor(new CommandsExecutor());
		Bukkit.getPluginCommand(name).setTabCompleter(new CommandsExecutor());
		// commands.add(new ExamplesCommand());
		commands.add(new ReloadCommand());
		commands.add(new SetCommand());
		commands.add(new StartCommand());
		commands.add(new GiveCommand());
		commands.add(new ItemCommand());
	}

	// 忽略大小写
	public SubCommand getSubCommand(String cmd) {
		for (SubCommand command : commands) {
			if (command.getName().equalsIgnoreCase(cmd)) {
				return command;
			}
		}
		return null;
	}

	public Set<SubCommand> getCommands() {
		return commands;
	}
}
